package com.sam.im.heiqun.uis.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sam.im.heiqun.R;
import com.sam.im.heiqun.entities.LiangSortItem;
import com.sam.im.heiqun.entities.MyGiftItem;
import com.yuyh.library.utils.GlideUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by wangguodong on 2017/8/21.
 */

public class LiangSortAdapter extends RecyclerView.Adapter <LiangSortAdapter.ViewHold>{
    private static final String TAG = "LiangSortAdapter";
    private Context mContext ;
    private List<LiangSortItem.ListBean> datas ;

    private int selecterNum = 0 ;

    public LiangSortAdapter(Context mContext, List<LiangSortItem.ListBean> datas){
        this.mContext = mContext ;
//        this.datas = null==datas?new String[0]:datas ;
        this.datas = datas ;
    }

    public int getSelecterNum(){
        return selecterNum ;
    }

    @Override
    public LiangSortAdapter.ViewHold onCreateViewHolder(ViewGroup parent, int viewType) {
        View headView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_my_gift_list, parent, false);
        return new ViewHold(headView);
    }

    @Override
    public void onBindViewHolder(LiangSortAdapter.ViewHold holder, final int position) {
        LiangSortItem.ListBean listBean = datas.get(position);

        if (position == selecterNum){
            holder.image_head.setBackgroundResource(R.drawable.checkbox_partial);
        }else {
            holder.image_head.setBackgroundResource(R.drawable.checkbox_unchecked);
        }

        holder.txt_name.setText(listBean.getTypeName());

        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int end = selecterNum ;
                selecterNum = position ;
                notifyItemChanged(end);
                notifyItemChanged(selecterNum);
            }
        });

//        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        Date d1=new Date(Long.parseLong(listBean.getCreateTime()));
//        String t1=format.format(d1);
//        holder.txt_time.setText(t1);

    }

    @Override
    public int getItemCount() {
        return null==datas?0:datas.size();
    }

    class ViewHold extends RecyclerView.ViewHolder{

        ImageView image_head ;
        TextView txt_name ;

        View view ;

        public ViewHold(View itemView) {
            super(itemView);
            view = itemView ;
            image_head = (ImageView) itemView.findViewById(R.id.image_head);
            txt_name = (TextView) itemView.findViewById(R.id.txt_name);
        }
    }

}
